package org.csu.mypetstore.web.account;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.csu.mypetstore.domain.Cart;
import org.csu.mypetstore.domain.CartItem;
import org.csu.mypetstore.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "newAccountForm",urlPatterns = "/newAccountForm")
public class NewAccountFormServlet extends HttpServlet {
    private static final String NEW_ACCOUNT = "/WEB-INF/jsp/account/NewAccountForm.jsp";
//    private CartService cartService = new CartService();
    private static final Logger logger = LogManager.getLogger(NewAccountFormServlet.class);

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        HttpSession session = req.getSession();
//        Cart cart = (Cart)session.getAttribute("cart");
//        if(cart != null){
//            for (CartItem c:cart.getCartItemList()) {
//                cartService.insertCartItem("",c);
//            }
//        }

        logger.info("A user trys to sign up");
        req.getRequestDispatcher(NEW_ACCOUNT).forward(req,resp);
    }
}
